import type { VueConstructor } from 'vue'

export type WithInstall<T> = T & {
  install(Vue: VueConstructor): void
}

export function withInstall<T extends VueConstructor>(component: T) {
  ;(component as Record<string, unknown>).install = (Vue: VueConstructor) => {
    const { name } = component

    if (name) {
      Vue.component(name, component)
    }
  }

  return component as WithInstall<T>
}
